package palmtop.com.palmtop.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;

import java.lang.reflect.Type;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import palmtop.com.palmtop.R;
import palmtop.com.palmtop.adapter.TaskAdapter;
import palmtop.com.palmtop.adapter.TaskgridAdapter;
import palmtop.com.palmtop.model.Task;
import palmtop.com.palmtop.model.Taskgrid;
import palmtop.com.palmtop.util.Config;
import palmtop.com.palmtop.util.NetUtil;

public class TaskgridActivity extends BaseActivity {

    @BindView(R.id.mtitle)
    TextView mtitle;
    @BindView(R.id.taskgridlList)
    ListView taskgridlList;

    private TaskgridAdapter adapter;
    Task task;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_taskgrid, Config.toptitle, 1);
        ButterKnife.bind(this);
        MyApplication app = (MyApplication) getApplication();
        app.addActivityList(TaskgridActivity.this);
        task = (Task)getIntent().getSerializableExtra("task");
        initView();

    }

    private void initView() {
        mtitle.setText("任务详情");
        if(task!=null){
            RequestParams params = new RequestParams(Config.SERVER_URL + "taskgridapp/getListByTaskid");
            params.addBodyParameter("orataskid",String.valueOf(task.getId()));
            NetUtil.postData(params, new Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    if(result!=null){
                        Gson gson = new Gson();
                        Type listType = new TypeToken<ArrayList<Taskgrid>>() {
                        }.getType();
                        final ArrayList<Taskgrid> list = gson.fromJson(result,listType);
                        adapter = new TaskgridAdapter(list,TaskgridActivity.this);
                        taskgridlList.setAdapter(adapter);
                        /*taskgridlList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                Intent intent = new Intent();
                                intent.putExtra("taskgrid",list.get(i));
                                intent.setClass(TaskgridActivity.this,ProcesstaskActivity.class);
                                startActivity(intent);
                            }
                        });*/
                    }
                }
                @Override
                public void onError(Throwable ex, boolean isOnCallback) {}
                @Override
                public void onCancelled(CancelledException cex) {}
                @Override
                public void onFinished() {}
            });
        }
    }
}
